package com.sky.mapper.user;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.pojo.Orders;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    /**
     * 插入订单数据
     * @param order
     */
    void insert(Orders order);

    @Select("select * from orders o where order_time < #{time} and status = 1")
    List<Orders> getCheckPayStatusOrders(LocalDateTime time);

    @Update("update orders set status = #{status},pay_status = #{payStatus} where id = #{id}")
    void updateOrderPaySuccess(Orders orders);

    @Update("update orders set status = #{status},pay_status = #{payStatus}, cancel_time = #{cancelTime},cancel_reason=#{cancelReason} where id = #{id}")
    void cancelOrder(Orders checkPayStatusOrder);

    @Select("select * from orders where number = #{number}")
    Orders selectByNumber(String number);

    /**
     * 根据id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders selectById(Long id);

    /**
     * 根据订单状态查询订单
     * @param status
     * @return
     */
    List<Orders> selectByStatus(Integer status);

    Page<OrderVO> conditionSearch(OrdersPageQueryDTO dto);

    @Select("select count(*) from orders where status = #{status}")
    Integer countStatus(Integer completeOrder);

    @Update("update orders set status = #{status},pay_status = #{payStatus}, cancel_time = #{cancelTime},rejection_reason=#{rejectionReason} where id = #{id}")
    void updateRejectionOrder(Orders checkPayStatusOrder);


    OrderStatisticsVO selectStatistics();
}
